﻿using System;

namespace EHR18
{
    public class SerialConfig
    {
        public string Name { get; set; }
        public string COM { get; set; }
        public string Baud { get; set; }
        public string Stopbits { get; set; }
        public string Parity { get; set; }
        public string Databits { get; set; }
        public override string ToString()
        {
            return string.Format("{0},{1},{2},{3},{4},{5}", Name, COM, Baud, Databits, Stopbits, Parity);
        }
        /// <summary>
        /// 构造函数 
        /// </summary>
        /// <param name="Cfg">配置字符串,例如：“PLC,COM1,9600,8,1,None”</param>
      public  SerialConfig(string Cfg)
        {
            try
            {
                string[] c = Cfg.Split(',');
                Name = c[0];
                COM = c[1];
                Baud = c[2];
                Databits = c[3];
                Stopbits = c[4];
                Parity = c[5];
            }
            catch 
            {
                throw new FormatException("串口配置字符串格式不正确"); 
            }
        }
        public SerialConfig()
        {
            Name =Guid.NewGuid().ToString();
            COM = "COM1";
            Baud = "9600";
            Databits = "8";
            Stopbits = "1";
            Parity ="None";
        }
    }
}
